home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / dos / close.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  3KB  |  148 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: close.c,v 1.5 1996/10/24 15:50:24 aros Exp $
  4.     $Log: close.c,v $
  5.     Revision 1.5  1996/10/24 15:50:24  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.4  1996/08/13 13:52:45  digulla
  9.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  10.     Replaced AROS_LA by AROS_LHA
  11.  
  12.     Revision 1.3  1996/08/12 14:17:34  digulla
  13.     Added alias UnLock Close
  14.  
  15.     Revision 1.2  1996/08/01 17:40:48  digulla
  16.     Added standard header for all files
  17.  
  18.     Desc:
  19.     Lang: english
  20. */
  21. #include <clib/exec_protos.h>
  22. #include <dos/dosextens.h>
  23. #include <dos/filesystem.h>
  24. #include <clib/dos_protos.h>
  25. #include "dos_intern.h"
  26.  
  27. /*****************************************************************************
  28.  
  29.     NAME */
  30.     #include <clib/dos_protos.h>
  31.  
  32.     AROS_LH1(BOOL, Close,
  33.  
  34. /*  SYNOPSIS */
  35.     AROS_LHA(BPTR, file, D1),
  36.  
  37. /*  LOCATION */
  38.     struct DosLibrary *, DOSBase, 6, Dos)
  39.  
  40. /*  FUNCTION
  41.     Close a filehandle opened with Open(). If the file was used
  42.     with buffered I/O the final write may fail and thus Close()
  43.     return an error. The file is closed in any case.
  44.  
  45.     INPUTS
  46.     file   - filehandle
  47.  
  48.     RESULT
  49.     0 if there was an error. !=0 on success.
  50.  
  51.     NOTES
  52.     This function is identical to Lock().
  53.  
  54.     EXAMPLE
  55.  
  56.     BUGS
  57.  
  58.     SEE ALSO
  59.  
  60.     INTERNALS
  61.  
  62.     HISTORY
  63.     29-10-95    digulla automatically created from
  64.                 dos_lib.fd and clib/dos_protos.h
  65.  
  66. *****************************************************************************/
  67.  
  68. /*****************************************************************************
  69.  
  70.     NAME
  71.     #include <clib/dos_protos.h>
  72.  
  73.     AROS_LH1(BOOL, UnLock,
  74.  
  75.     SYNOPSIS
  76.     AROS_LHA(BPTR, lock, D1),
  77.  
  78.     LOCATION
  79.     struct DosLibrary *, DOSBase, 15, Dos)
  80.  
  81.     FUNCTION
  82.     Free a lock created with Lock().
  83.  
  84.     INPUTS
  85.     lock - The lock to free
  86.  
  87.     RESULT
  88.  
  89.     NOTES
  90.     This function is identical to Close() - see there.
  91.  
  92.     EXAMPLE
  93.  
  94.     BUGS
  95.  
  96.     SEE ALSO
  97.  
  98.     INTERNALS
  99.  
  100.     HISTORY
  101.     29-10-95    digulla automatically created from
  102.                 dos_lib.fd and clib/dos_protos.h
  103.  
  104. *****************************************************************************/
  105. /*AROS alias UnLock Close */
  106. {
  107.     AROS_LIBFUNC_INIT
  108.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  109.  
  110.     /* Get pointer to filehandle */
  111.     struct FileHandle *fh=(struct FileHandle *)BADDR(file);
  112.  
  113.     /* Get pointer to process structure */
  114.     struct Process *me=(struct Process *)FindTask(NULL);
  115.  
  116.     /* Get pointer to I/O request. Use stackspace for now. */
  117.     struct IOFileSys io,*iofs=&io;
  118.  
  119.     /* The returncode defaults to OK. */
  120.     BOOL ret=1;
  121.  
  122.     /* 0 handles are OK */
  123.     if(!file)
  124.     return ret;
  125.  
  126.     /* If the filehandle has a pending write on it Flush() the buffer. */
  127.     if(fh->fh_Flags&FHF_WRITE)
  128.     ret=Flush(file);
  129.  
  130.     /* Prepare I/O request. */
  131.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  132.     iofs->IOFS.io_Message.mn_ReplyPort     =&me->pr_MsgPort;
  133.     iofs->IOFS.io_Message.mn_Length     =sizeof(struct IOFileSys);
  134.     iofs->IOFS.io_Device =fh->fh_Device;
  135.     iofs->IOFS.io_Unit     =fh->fh_Unit;
  136.     iofs->IOFS.io_Command=FSA_CLOSE;
  137.     iofs->IOFS.io_Flags  =0;
  138.  
  139.     /* Send the request. No errors possible. */
  140.     (void)DoIO(&iofs->IOFS);
  141.  
  142.     FreeDosObject(DOS_FILEHANDLE,fh);
  143.  
  144.     /* All done. */
  145.     return ret;
  146.     AROS_LIBFUNC_EXIT
  147. } /* Close */
  148.